package common;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;

import com.mysql.opt.Operator;

public class BlobTypeStringReader {
	
	public static String readToString(Object obj){
		String stat = "";
		try{			
			//System.out.println(obj.getClass().getCanonicalName());
			if(obj!=null && obj.getClass().getCanonicalName().equalsIgnoreCase("byte[]")){
				byte[] b = (byte[])obj;
				BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(b)));
				String tmp = null;
				while((tmp=br.readLine())!=null){
					stat += tmp + Operator.nextline;
				}
				if(stat.endsWith(Operator.nextline)){
					stat = stat.substring(0, stat.length() - Operator.nextline.length());
				}
				br.close();
				return stat;
			}else{
				return null;
			}
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}		
	}

}
